package com.heyqing.topic.SumOfLeftLeaves_0404;

import java.util.Objects;

/**
 * ClassName:SumOfLeftLeaves
 * Package:com.heyqing.topic.SumOfLeftLeaves_0404
 * Description:
 *
 * @Date:2024/9/28
 * @Author:Heyqing
 */
public class SumOfLeftLeaves {

    private int sum = 0;

    public int sumOfLeftLeaves(TreeNode root) {
        boolean flag = false;
        achieveFunc(root, flag);
        return sum;
    }

    private void achieveFunc(TreeNode root, boolean flag) {
        if (Objects.isNull(root)) return;
        if (flag && Objects.isNull(root.left) && Objects.isNull(root.right)) sum += root.val;
        achieveFunc(root.left, true);
        achieveFunc(root.right, false);
    }
}
